/*
 * SimpleAssignInstruction.java
 * 
 * last update: 16.01.2010 by Stefan Saru
 * 
 * author:	Alec(panovici@elcom.pub.ro)
 * 
 * Obs:
 */

package engine;

/**
 *  This is used to complete the non-blocking and wire assignement
 * at the end of the time unit. It's not delayed. The value is determined
 * at the time of the non-blocking assignement exectution, and the assignement
 * is programmed by appending a SimpleAssignInstruction in the Time.finishList
 * FIFO vector.
 */
@SuppressWarnings("serial")
class SimpleAssignInstruction extends DefaultInstruction{
  LeftValue lv;
  Result r;
  boolean active;
  String message;
  
  SimpleAssignInstruction (NameSpace ns, LeftValue lv,
                           Result r, String message){
    super(ns, 0, null);
    this.r = r;
    this.lv = lv;
    active = true;
    this.message = message;
  }

  public void inhibate(){
    active = false;
  }
  
  public void execute()
    throws InterpretTimeException, SimulationStoppedException
  {  
    if(active){
      if (message != null)
        xConsole.trace(message);            
      try{
        lv.assign(r);
        Thread.yield();  //give monitors a time to breath
      }catch(InterpretTimeException ex){
        xConsole.dumpStack(ex);
        throw new
          InterpretTimeException("Size does not match in attrib. :" + toString());
      }
    } 
  }

  public String toString() {
    return lv + "<-" + r;
  }

}



